package com.shanjupay.test.freemarker.controller;

import com.shanjupay.test.freemarker.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;

/**
 * @className: FreemarkerController
 * @Description: TODO
 * @author: Huangjianyun
 * @date: 2021/10/18 23:54
 */
//返回添加map 渲染模板的页面
@Controller
public class FreemarkerController {

    //模板数据一般以形参形式作为参数进行传递
    @RequestMapping("/test1")
    public String freemark(Map<String,Object>  model){
        //设置数据模型，key:name value：world
        model.put("name","world");

        Student stu1 = new Student();
 //       stu1.setName("小明");
        stu1.setAge(18);
        stu1.setMoney(1000.86f);
        stu1.setBirthday(new Date());
        Student stu2 = new Student();
        stu2.setName("小红");
        stu2.setMoney(200.1f);
        stu2.setAge(19);
//        stu2.setBirthday(new Date());
        List<Student> friends = new ArrayList<>();
        friends.add(stu1);
        stu2.setFriends(friends);
        stu2.setBestFriend(stu1);
        List<Student> stus = new ArrayList<>();
        stus.add(stu1);
        stus.add(stu2);
        //向数据模型放数据
       // model.put("stus",stus);
        //准备map数据
        HashMap<String, Student> stuMap = new HashMap<>();
        stuMap.put("stu1",stu1);
        stuMap.put("stu2",stu2);
        //向数据模型放数据
        model.put("stu1",stu1);
        //向数据模型放数据
        model.put("stuMap",stuMap);
        //返回渲染的模板页面
        return "test1";
    }

}
